try:
    UART = __import__('machine').UART(0)

    render = None

    active = True

    def begin():
        global active, UART
        if active:
            os.dupterm( None , 1)
            active = False

    def end():
        global active, UART
        if not active :
            os.dupterm( UART , 1)
            active = True

    def echo(input=None):
        global UART
        if input is not None:
            end()
            sys.stdout.write(input)
        begin()

except ValueError:
    print(b"esp32 UART reserved".decode())

    def begin():pass
    def end():pass

    def echo(input=None):
        if input is not None:
            sys.stdout.write(input)
